package edu.pku.sei.mte.mtemodel.mtmodel.common;

import edu.pku.sei.mte.constants.MDAConstant;
import edu.pku.sei.mte.mtemodel.core.DataType;
import edu.pku.sei.mte.mtemodel.core.Element;
import edu.pku.sei.mte.mtemodel.core.NamedElement;
import edu.pku.sei.mte.mtemodel.core.TypedElement;
import edu.pku.sei.mte.utilities.Visitor;

public class Variable extends Element implements TypedElement, NamedElement{

	private String name;
	private DataType type;
	private Object value;
	
	public Variable(){
		value = UNINITIATED_VALUE;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public DataType getType() {
		return type;
	}
	public void setType(DataType type) {
		this.type = type;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	
	public boolean isValid(){
		if(value==null||value==UNINITIATED_VALUE)
			return false;
		return true;
	}
	
	public static final Object ERROR_VALUE = MDAConstant.ERROR_VALUE;
	public static final Object UNINITIATED_VALUE = MDAConstant.UNINITIATED_VALUE;

	public Variable getCopy(){
		Variable v = new Variable();
		v.copy(this);
		return v;
	}
	
	protected void copy(Variable v){
		name = v.name;
		type = v.type;
		value = v.value;
	}

	@Override
	public String toString() {
		return "("+name+"="+value+")";
	}
	
	@Override
	public Object accept(Visitor visitor) {
		return visitor.visitVariable(this);
	}

}
